package com.peng.sell.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CookieUtil {
    public static void set(HttpServletResponse response,String key,String value,Integer expire){
        Cookie cookie = new Cookie(key,value);
        cookie.setPath("/");
        cookie.setMaxAge(expire);
        response.addCookie(cookie);
    }

    public static Cookie get(HttpServletRequest request, String key){
        if(request.getCookies()!=null){
            for (Cookie cookie : request.getCookies()){
                switch (cookie.getName()){
                    case "token":
                        return cookie;
                    default:
                        break;
                }
            }
        }

        return null;

    }
}
